package com.lianjinsu.shop.repository.dao.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.lianjinsu.shop.core.mybatis.AdvancedDaoImpl;
import com.lianjinsu.shop.entity.Banner;
import com.lianjinsu.shop.repository.dao.BannerDao;
import com.lianjinsu.shop.repository.mapper.BannerMapper;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Locale;

@Repository
public class BannerDaoImpl extends AdvancedDaoImpl<BannerMapper, Banner> implements BannerDao {

    @Override
    public List<Banner> selectSortDesc(int limit) {
        LambdaQueryWrapper<Banner> wrapper = Wrappers.lambdaQuery();
        wrapper.orderByDesc(Banner::getSort);
        wrapper.last(String.format(Locale.ROOT, "LIMIT %s", limit));
        return baseMapper.selectList(wrapper);
    }
}
